/**
 * Description: RegisterLargeItemDAOImpl.java
 * Copyright (c) 2008-2009  Neo. 
 * All Rights Reserved.
 * @version 1.0  Apr 3, 2009 5:59:03 PM 李萌（neolimeng@gmail.com）created
 */
package org.paradise.dms.dao.impl;

import java.sql.SQLException;
import java.util.Date;
import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.SQLQuery;
import org.hibernate.Session;
import org.paradise.dms.pojo.RegisterLargeItem;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.stereotype.Service;

import com.dheaven.framework.dao.BaseHibernateDao;
import com.dheaven.framework.dao.DaoException;

/**
 * Description: Copyright (c) 2008-2009 Neo. All Rights Reserved.
 * 
 * @version 1.0 Apr 3, 2009 5:59:03 PM 李萌（neolimeng@gmail.com）created
 */
@Service
public class RegisterLargeItemDAOImpl extends
		BaseHibernateDao<RegisterLargeItem> {

	public void insertRegisterLargeItem(RegisterLargeItem rlt)
			throws DaoException {
		this.create(rlt);
	}

	public void updateRegisterLargeItem(RegisterLargeItem rlt)
			throws DaoException {
		this.update(rlt);
	}

	public void deleteRegisterLargeItem(int rltid) {
		SQLQuery sqlQuery = (SQLQuery) this
				.getSession()
				.createSQLQuery(
						"update registerlargeitem set registerlargeitemind=0 where registerlargeitemid=?")
				.setInteger(0, rltid);
		sqlQuery.executeUpdate();
	}

	public RegisterLargeItem getRegisterLargeItem(int rliid)
			throws DaoException {
		return (RegisterLargeItem) this
				.find(
						"from RegisterLargeItem where registerlargeitemid=? and registerlargeitemind=1",
						new Object[] { rliid });
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLargeItem> getAllRegisterLargeItem() {
		List<RegisterLargeItem> lrli = this
				.find("from RegisterLargeItem where registerlargeitemind=1");
		return lrli;
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLargeItem> getAllRegisterLargeItemIn() {
		List<RegisterLargeItem> lrli = this
				.find("from RegisterLargeItem where registerlargeitemind=1 and inorout=0");
		return lrli;
	}

	@SuppressWarnings("unchecked")
	public int getAllRowsIn() {
		List<RegisterLargeItem> list = this
				.find("from RegisterLargeItem where inorout=0 and registerlargeitemind=1");
		return list.size();
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLargeItem> listAllRegisterLargeItemIn(int pageSize,
			int startRow) {
		final int pageSize1 = pageSize;
		final int startRow1 = startRow;
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public List doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session
						.createQuery("from RegisterLargeItem where inorout=0 and registerlargeitemind=1");
				query.setFirstResult(startRow1);
				query.setMaxResults(pageSize1);
				return query.list();
			}
		});
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLargeItem> getAllRegisterLargeItemOut() {
		List<RegisterLargeItem> lrli = this
				.find("from RegisterLargeItem where registerlargeitemind=1 and inorout=1");
		return lrli;
	}
	
	@SuppressWarnings("unchecked")
	public int getAllRowsOut() {
		List<RegisterLargeItem> list = this
				.find("from RegisterLargeItem where inorout=1 and registerlargeitemind=1");
		return list.size();
	}

	@SuppressWarnings("unchecked")
	public List<RegisterLargeItem> listAllRegisterLargeItemOut(int pageSize,
			int startRow) {
		final int pageSize1 = pageSize;
		final int startRow1 = startRow;
		return this.getHibernateTemplate().executeFind(new HibernateCallback() {
			public List doInHibernate(Session session)
					throws HibernateException, SQLException {
				Query query = session
						.createQuery("from RegisterLargeItem where inorout=1 and registerlargeitemind=1");
				query.setFirstResult(startRow1);
				query.setMaxResults(pageSize1);
				return query.list();
			}
		});
	}

	public void setRegisterLargeItemInToOut(int rliid) {
		SQLQuery sqlQuery = (SQLQuery) this
				.getSession()
				.createSQLQuery(
						"update registerlargeitem set registerlargeitemouttime=? where registerlargeitemid=?")
				.setTimestamp(0, new Date()).setInteger(1, rliid);
		sqlQuery.executeUpdate();
	}

	public void setRegisterLargeItemOutToIn(int rliid) {
		SQLQuery sqlQuery = (SQLQuery) this
				.getSession()
				.createSQLQuery(
						"update registerlargeitem set registerlargeitemintime=? where registerlargeitemid=?")
				.setTimestamp(0, new Date()).setInteger(1, rliid);
		sqlQuery.executeUpdate();
	}
}
